

#include "atomic_op_asm.h"

ENTRY_NP(_atomic_cas_32)
	mov	x4, x0			/* we need r0 for return value */
1:	ldxr	w0, [x4]		/* load old value */
	cmp	w0, w1			/*   compare? */
	b.ne	2f			/*     return if different */
	stxr	w3, w2, [x4]		/* store new value */
	cbnz	w3, 1b			/*   succeed? nope, try again. */
	dmb	st
2:	ret				/* return. */
END(_atomic_cas_32)

ATOMIC_OP_ALIAS(atomic_cas_32,_atomic_cas_32)
ATOMIC_OP_ALIAS(atomic_cas_uint,_atomic_cas_32)
ATOMIC_OP_ALIAS(atomic_cas_32_ni,_atomic_cas_32)
ATOMIC_OP_ALIAS(atomic_cas_uint_ni,_atomic_cas_32)
STRONG_ALIAS(__sync_val_compare_and_swap_4,_atomic_cas_32)
STRONG_ALIAS(_atomic_cas_uint,_atomic_cas_32)
STRONG_ALIAS(_atomic_cas_32_ni,_atomic_cas_32)
STRONG_ALIAS(_atomic_cas_uint_ni,_atomic_cas_32)
